home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / GameCharacter.as < prev    next >
Text File  |  2006-11-29  |  26KB  |  894 lines

  1. class GameCharacter extends SSObject
  2. {
  3.    var radius = 22.5;
  4.    var jumpStrength = 400;
  5.    var gravity = SSGlobal.GRAVITY;
  6.    var maxWalkForce = 900;
  7.    var maxAirForce = 200;
  8.    var mass = 1;
  9.    var drag = 0.5;
  10.    var classID = SSGlobal.CLSID_MAINCHAR;
  11.    var collisionMask = 4294967295;
  12.    var assetID = "Character";
  13.    var animationLabels = ["idle","walk","airUp","airDown","hurt","death","deathInAir","end","climbHold","climbUp","climbDown","carry","carryWalk"];
  14.    var animationLabel = 0;
  15.    var active = false;
  16.    var keysLocked = false;
  17.    var sp = false;
  18.    var shieldCMax = {rb:255,gb:192,bb:0};
  19.    var depthLayer = 4;
  20.    var dispState = 0;
  21.    var dispCanTurn = true;
  22.    var dispAxis = 1;
  23.    var dispTurn = 0;
  24.    var dispTurnTime = 0.25;
  25.    var dispTurnFrames = 4;
  26.    var dispFrame = GameCharacter.prototype.dispTurnFrames;
  27.    var dispStateChanged = false;
  28.    var runTick = 0;
  29.    var eLast = 0;
  30.    var eInterval = 0.1;
  31.    var eTime = 0;
  32.    var eTimeTotal = 0;
  33.    var eLID = 0;
  34.    var canClimb = true;
  35.    var canSwing = true;
  36.    var climbLimit = false;
  37.    var corrected = false;
  38.    var inMotion = 1;
  39.    var inMotionTime = 0.25;
  40.    var canCarry = true;
  41.    var carryingTime = 0;
  42.    var jumpTime = 0;
  43.    var allowJumpTime = 0.2;
  44.    var directionX = 1;
  45.    var climbSpeed = 100;
  46.    var swinging = null;
  47.    var speed = 0;
  48.    var lastClimbTime = 0;
  49.    var multiplier = 1;
  50.    var health = 1;
  51.    var shield = 0;
  52.    var maxShield = 30;
  53.    var immune = 0;
  54.    var immuneAllowed = 3;
  55.    var immuneAtStart = 3;
  56.    var immuneBlink = 0.1;
  57.    var lockDisplayState = false;
  58.    var canLockDisplayState = true;
  59.    var finished = false;
  60.    var dead = false;
  61.    function GameCharacter()
  62.    {
  63.       super();
  64.       this.acceleration = new Vector();
  65.       this.contactNormal = new Vector();
  66.    }
  67.    function initColor()
  68.    {
  69.       if(this.colorObj)
  70.       {
  71.          var _loc2_ = this.colorObj.getTransform();
  72.       }
  73.       this.colorObj = new Color(this.target);
  74.       if(_loc2_)
  75.       {
  76.          this.colorObj.setTransform(_loc2_);
  77.       }
  78.    }
  79.    function onAddDisplay()
  80.    {
  81.       this.initColor();
  82.       this.buildAnimationData();
  83.    }
  84.    function activate()
  85.    {
  86.       this.world.viewport.setWatch(this);
  87.       this.lockDisplayState = false;
  88.       this.immune = this.immuneAtStart;
  89.       this.target._visible = true;
  90.       this.keepInScene = true;
  91.       this.controller.fuel = 0;
  92.       this.health = this.controller.health;
  93.    }
  94.    function deactivate()
  95.    {
  96.       this.toss();
  97.       this.moveTo(-300,0,0);
  98.    }
  99.    function buildAnimationData()
  100.    {
  101.       this.animationFrames = [];
  102.       var _loc2_ = this.animationLabels.length;
  103.       while((_loc2_ = _loc2_ - 1) > -1)
  104.       {
  105.          this.target.gotoAndStop(this.animationLabels[_loc2_]);
  106.          if(this.target._currentframe != 1)
  107.          {
  108.             if(this.target.a)
  109.             {
  110.                this.animationFrames[_loc2_] = Math.floor(this.target.a._totalframes * 0.5);
  111.             }
  112.          }
  113.       }
  114.       this.setAnimationState(0,true);
  115.    }
  116.    function update(elapsed)
  117.    {
  118.       if(!this.keysLocked)
  119.       {
  120.          var _loc4_ = this.controller.right - this.controller.left;
  121.          var _loc3_ = this.controller.down - this.controller.up;
  122.          var _loc5_ = this.sp != (this.sp = this.controller.jump) && this.sp;
  123.          if(this.canClimb && !this.climbing && !this.swinging && _loc3_ && this.lastClimbingObject && this.lastClimbTime + 0.5 < this.world.time)
  124.          {
  125.             if(this.x <= this.lastClimbingObject.right && this.x >= this.lastClimbingObject.left && this.y <= this.lastClimbingObject.bottom && this.y >= this.lastClimbingObject.top)
  126.             {
  127.                this.climbing = this.lastClimbingObject;
  128.                this.contactSurface = null;
  129.             }
  130.          }
  131.       }
  132.       else
  133.       {
  134.          _loc4_ = 0;
  135.          _loc3_ = 0;
  136.          var _loc0_ = null;
  137.          _loc5_ = this.sp = 0;
  138.       }
  139.       if(this.eTime)
  140.       {
  141.          this.eTime = Math.max(this.eTime - elapsed,0);
  142.          this.dropParticle();
  143.       }
  144.       if(this.shield)
  145.       {
  146.          if((this.shield -= elapsed) < 0)
  147.          {
  148.             this.onShieldEnd();
  149.          }
  150.          else
  151.          {
  152.             this.onShield();
  153.          }
  154.       }
  155.       else if(this.immune)
  156.       {
  157.          if(!(this.immune = Math.max(this.immune - elapsed,0)))
  158.          {
  159.             this.target._visible = true;
  160.          }
  161.          else
  162.          {
  163.             this.target._visible = Boolean(Math.floor(this.immune / this.immuneBlink) % 3);
  164.          }
  165.       }
  166.       this.updatePosition(elapsed,_loc4_,_loc3_,_loc5_);
  167.       if(!this.lockDisplayState)
  168.       {
  169.          this.updateDisplay(elapsed,_loc4_,_loc3_,_loc5_);
  170.       }
  171.       this.onUpdate(elapsed);
  172.    }
  173.    function onShieldEnd()
  174.    {
  175.       this.immune = this.shield = 0;
  176.       this.colorObj.setTransform({rb:0,gb:0,bb:0});
  177.    }
  178.    function onShield()
  179.    {
  180.       var _loc2_ = {};
  181.       var _loc3_ = Math.abs(Math.sin(Math.log(this.shield + 1) * 10));
  182.       _loc2_.rb = _loc3_ * this.shieldCMax.rb;
  183.       _loc2_.gb = _loc3_ * this.shieldCMax.gb;
  184.       _loc2_.bb = _loc3_ * this.shieldCMax.bb;
  185.       this.colorObj.setTransform(_loc2_);
  186.    }
  187.    function setAnimationState(state, force)
  188.    {
  189.       if(state == this.dispState && !force)
  190.       {
  191.          return undefined;
  192.       }
  193.       this.dispState = state;
  194.       this.dispTurnFrames = this.animationFrames[state];
  195.       this.target.gotoAndStop(this.animationLabels[state]);
  196.       this.target.a.gotoAndStop(this.directionX >= 0 ? this.target.a._totalframes : 1);
  197.       this.dispStateChanged = true;
  198.    }
  199.    function updateDisplay(elapsed, vX, vY, kJump)
  200.    {
  201.       if(this.swinging)
  202.       {
  203.          this.target._rotation = Math.atan2(- this.swinging.vx,this.swinging.vy) / 3.141592653589793 * 180;
  204.          this.setAnimationState(8);
  205.       }
  206.       else if(this.carrying)
  207.       {
  208.          if(this.jumpTime && vX)
  209.          {
  210.             this.setAnimationState(12);
  211.          }
  212.          else
  213.          {
  214.             this.setAnimationState(11);
  215.          }
  216.       }
  217.       else if(this.climbing)
  218.       {
  219.          if(!this.climbLimit && vY < 0)
  220.          {
  221.             this.setAnimationState(9);
  222.          }
  223.          else if(!this.climbLimit && vY > 0)
  224.          {
  225.             this.setAnimationState(10);
  226.          }
  227.          else
  228.          {
  229.             this.setAnimationState(8);
  230.          }
  231.       }
  232.       else if(this.contactSurface)
  233.       {
  234.          if(vX)
  235.          {
  236.             this.setAnimationState(1);
  237.             this.runTick += Math.max(0.005,elapsed * (this.speed / 400));
  238.             var _loc2_ = this.target.a.mcAnim;
  239.             if(this.runTick > 0.02)
  240.             {
  241.                this.runTick = 0;
  242.                if(_loc2_._currentframe == _loc2_._totalframes)
  243.                {
  244.                   _loc2_.gotoAndStop(1);
  245.                }
  246.                else
  247.                {
  248.                   _loc2_.nextFrame();
  249.                }
  250.             }
  251.             else
  252.             {
  253.                _loc2_.stop();
  254.             }
  255.          }
  256.          else
  257.          {
  258.             this.setAnimationState(0);
  259.          }
  260.       }
  261.       else if(!this.jumpTime)
  262.       {
  263.          if(this.velocity.y < 0)
  264.          {
  265.             this.setAnimationState(2);
  266.          }
  267.          else
  268.          {
  269.             this.setAnimationState(3);
  270.          }
  271.       }
  272.       if(this.dispCanTurn && vX && vX != this.dispAxis)
  273.       {
  274.          this.directionX = this.dispTurn = vX;
  275.       }
  276.       if(this.dispStateChanged || this.dispTurn)
  277.       {
  278.          if(this.dispTurn)
  279.          {
  280.             if(this.dispTurn > 0)
  281.             {
  282.                if((this.dispAxis = Math.min(1,this.dispAxis += elapsed * 2 / this.dispTurnTime)) == 1)
  283.                {
  284.                   this.dispTurn = 0;
  285.                }
  286.             }
  287.             else if((this.dispAxis = Math.max(-1,this.dispAxis -= elapsed * 2 / this.dispTurnTime)) == -1)
  288.             {
  289.                this.dispTurn = 0;
  290.             }
  291.          }
  292.          this.dispFrame = this.dispTurnFrames + Math.round(this.dispAxis * this.dispTurnFrames) + 1;
  293.          this.target.a.gotoAndStop(this.dispFrame);
  294.       }
  295.       this.dispStateChanged = false;
  296.    }
  297.    function emitParticle(linkageID, time, options)
  298.    {
  299.       if(linkageID == null)
  300.       {
  301.          this.eTime = 0;
  302.          this.eLID = null;
  303.          return undefined;
  304.       }
  305.       this.eTime = this.eTimeTotal = time;
  306.       this.eLID = linkageID;
  307.       if(options)
  308.       {
  309.          this.eOptions = options;
  310.       }
  311.       else
  312.       {
  313.          delete this.eOptions;
  314.       }
  315.    }
  316.    function dropParticle()
  317.    {
  318.       if(this.eLast == (this.eLast = Math.floor(this.eTime / this.eInterval)))
  319.       {
  320.          return undefined;
  321.       }
  322.       var _loc2_ = new SSParticle(this.eLID,!this.eOptions.life ? 1 : this.eOptions.life,new Vector(this.velocity.x * 0.1,this.velocity.y * 0.1 - 150,-20),this.eOptions.spin,this.eOptions.gravity);
  323.       _loc2_.x = this.x;
  324.       _loc2_.y = this.y;
  325.       _loc2_.scale = 150;
  326.       this.world.addObject(_loc2_);
  327.    }
  328.    function updatePosition(elapsed, vX, vY, kJump)
  329.    {
  330.       this.corrected = false;
  331.       var _loc6_ = this.x;
  332.       var _loc5_ = this.y;
  333.       this.jumpTime = Math.max(this.jumpTime - elapsed,0);
  334.       if(this.controller.action)
  335.       {
  336.          if(this.carrying)
  337.          {
  338.             this.toss();
  339.          }
  340.          else if(this.lastContainer)
  341.          {
  342.             this.pickup(this.lastContainer);
  343.          }
  344.       }
  345.       if(this.swinging)
  346.       {
  347.          if(kJump)
  348.          {
  349.             this.releaseSwing();
  350.          }
  351.          else
  352.          {
  353.             this.swingDist += (this.swinging.length - 50 - this.swingDist) * elapsed;
  354.             this.velocity.x = (this.swinging.x + this.swinging.vx * this.swingDist - this.x) / elapsed;
  355.             this.velocity.y = (this.swinging.y + this.swinging.vy * this.swingDist - this.y) / elapsed;
  356.          }
  357.       }
  358.       else if(this.climbing)
  359.       {
  360.          if(kJump)
  361.          {
  362.             this.releaseClimb();
  363.             this.jump(elapsed,vX,vY);
  364.             this.velocity.x = this.dispAxis * 200;
  365.             this.velocity.y = -300;
  366.          }
  367.          else
  368.          {
  369.             this.climb(elapsed,vX,vY);
  370.          }
  371.       }
  372.       else if(!this.inMotion || this.contactSurface)
  373.       {
  374.          if(kJump)
  375.          {
  376.             this.jump(elapsed,vX,vY);
  377.          }
  378.          else
  379.          {
  380.             this.walk(elapsed,vX,vY);
  381.          }
  382.       }
  383.       else if(this.jumpTime && kJump)
  384.       {
  385.          this.jump(elapsed,vX,vY);
  386.       }
  387.       else
  388.       {
  389.          this.updateInSpace(elapsed,vX,vY);
  390.       }
  391.       this.contactSurface = null;
  392.       this.checkCollisions(elapsed);
  393.       this.moveBy(this.velocity.x * this.motionTime,this.velocity.y * this.motionTime,0);
  394.       if(this.carrying)
  395.       {
  396.          this.carrying.moveTo(this.x,this.top - this.carrying.radius,0);
  397.       }
  398.       if(this.jumpTime && !vX && Math.abs(_loc6_ - this.x) < 1 && Math.abs(_loc5_ - this.y) < 1)
  399.       {
  400.          if(!(this.inMotion = Math.max(this.inMotion -= elapsed,0)))
  401.          {
  402.             this.velocity.x = 0;
  403.             this.velocity.y = 20;
  404.             this.moveTo(_loc6_,_loc5_,0);
  405.          }
  406.       }
  407.       else
  408.       {
  409.          this.inMotion = this.inMotionTime;
  410.       }
  411.    }
  412.    function onSurfaceContact()
  413.    {
  414.       if(this.climbing)
  415.       {
  416.          this.releaseClimb();
  417.       }
  418.       else if(this.swinging)
  419.       {
  420.          this.releaseSwing();
  421.       }
  422.       if(!this.jumpTime)
  423.       {
  424.          GameSound.playSound(this.contactSurface.attributes.impactSound);
  425.       }
  426.       this.jumpTime = this.contactNormal.y > 0 ? 0 : this.allowJumpTime;
  427.    }
  428.    function toss()
  429.    {
  430.       if(this.carryingTime + 0.2 < this.world.time)
  431.       {
  432.          this.carrying.setVelocity(new Vector(this.velocity.x + this.dispAxis * 200,this.velocity.y - 100,0));
  433.          this.carryingTime = this.world.time;
  434.          this.carrying = null;
  435.       }
  436.    }
  437.    function pickup()
  438.    {
  439.       if(this.canCarry && !this.lastContainer || this.lastContainer.inMotion)
  440.       {
  441.          return undefined;
  442.       }
  443.       var _loc3_ = this.lastContainer.x - this.x;
  444.       var _loc2_ = this.lastContainer.y - this.y;
  445.       if(Math.sqrt(_loc3_ * _loc3_ + _loc2_ * _loc2_) < this.lastContainer.radius + this.radius)
  446.       {
  447.          this.carrying = this.lastContainer;
  448.          this.carrying.beingCarried = true;
  449.          this.carryingTime = this.world.time;
  450.       }
  451.    }
  452.    function climb(elapsed, vX, vY)
  453.    {
  454.       this.velocity.x = 0.1;
  455.       this.velocity.y = vY * this.climbSpeed;
  456.       this.x = this.climbing.x + this.climbing.localRight * 0.5;
  457.       this.lockDisplayState = false;
  458.       if(vY)
  459.       {
  460.          if(vY < 0)
  461.          {
  462.             var _loc2_ = this.climbing.top - (this.top + this.velocity.y * elapsed);
  463.             if(_loc2_ > 0)
  464.             {
  465.                this.velocity.y *= _loc2_ / this.velocity.y;
  466.             }
  467.          }
  468.          else if(this.climbing.bottom - (this.top + this.velocity.y * elapsed) < 0)
  469.          {
  470.             this.releaseClimb();
  471.          }
  472.       }
  473.    }
  474.    function startSwing(obj, dist)
  475.    {
  476.       if(!this.canSwing || this.swinging || this.climbing || obj.swingRelease + 0.5 > this.world.time)
  477.       {
  478.          return undefined;
  479.       }
  480.       if(this.carrying)
  481.       {
  482.          this.toss();
  483.       }
  484.       obj.holding = this;
  485.       this.swingDist = dist;
  486.       this.swinging = obj;
  487.    }
  488.    function releaseSwing()
  489.    {
  490.       this.velocity.x = this.swinging.vx * 300;
  491.       this.velocity.y = (this.swinging.vy - 1) * 400;
  492.       this.target._rotation = 0;
  493.       this.swinging.holding = null;
  494.       this.swinging.swingRelease = this.world.time;
  495.       this.swinging = null;
  496.    }
  497.    function releaseClimb()
  498.    {
  499.       this.lastClimbTime = this.world.time;
  500.       this.climbing = null;
  501.    }
  502.    function jump(elapsed, vX, vY)
  503.    {
  504.       var _loc2_ = new Vector(this.contactNormal.x,this.contactNormal.y - 2,0);
  505.       _loc2_.normalize();
  506.       this.velocity.x += _loc2_.x * this.jumpStrength;
  507.       this.velocity.y += _loc2_.y * this.jumpStrength;
  508.       this.jumpTime = 0;
  509.    }
  510.    function walk(elapsed, vx, vy)
  511.    {
  512.       if(!this.contactSurface)
  513.       {
  514.          return undefined;
  515.       }
  516.       var _loc5_ = this.contactSurface.attributes;
  517.       if(this.contactSurface.props & 2)
  518.       {
  519.          var _loc6_ = _loc5_.friction;
  520.          var _loc9_ = _loc5_.traction;
  521.          this.force = new Vector((- this.contactNormal.y) * vx * this.maxWalkForce * _loc9_,this.contactNormal.x * vx * this.maxWalkForce * _loc9_ + this.gravity * (!vx ? 1 : 0.25),0);
  522.       }
  523.       else
  524.       {
  525.          this.force = new Vector();
  526.          _loc6_ = 0;
  527.          _loc9_ = 0;
  528.       }
  529.       var _loc8_ = 0.004 * this.velocity.x * this.velocity.x * (this.velocity.x < 0 ? 1 : -1);
  530.       var _loc7_ = 0.004 * this.velocity.y * this.velocity.y * (this.velocity.y < 0 ? 1 : -1);
  531.       var _loc3_ = this.contactNormal.dot(this.force);
  532.       var _loc2_ = this.velocity.getNormalized();
  533.       _loc2_.x *= _loc3_ * _loc6_;
  534.       _loc2_.y *= _loc3_ * _loc6_;
  535.       this.force.x += _loc2_.x + _loc8_;
  536.       this.force.y += _loc2_.y + _loc7_;
  537.       if(!this.inMotion && vx)
  538.       {
  539.       }
  540.       this.velocity.x += this.force.x * (1 / this.mass) * elapsed;
  541.       this.velocity.y += this.force.y * (1 / this.mass) * elapsed;
  542.    }
  543.    function updateInSpace(elapsed, vX, vY)
  544.    {
  545.       this.acceleration.x = (- this.velocity.x) * this.drag + vX * this.maxAirForce;
  546.       this.acceleration.y = (- this.velocity.y) * this.drag + this.gravity;
  547.       this.velocity.x += this.acceleration.x * elapsed;
  548.       this.velocity.y += this.acceleration.y * elapsed;
  549.    }
  550.    function checkCollision(obj, flag, options)
  551.    {
  552.       var _loc4_ = undefined;
  553.       switch(obj.classID & 4294901760)
  554.       {
  555.          case SSGlobal.CLSID_MOBILEOBJECT:
  556.          case SSGlobal.CLSID_MAINCHAR:
  557.             if(SSCollision.sweepBoundsToBounds(this,obj))
  558.             {
  559.                var _loc5_ = obj.onCollision(this);
  560.                this.collisionData = null;
  561.                return _loc5_ == null ? true : _loc5_;
  562.             }
  563.             break;
  564.          case SSGlobal.CLSID_CONTAINER:
  565.          case SSGlobal.CLSID_OBJECT:
  566.             if(!this.swinging && this.controller.up && obj.classID == SSGlobal.CLSID_SWING)
  567.             {
  568.                var _loc3_ = Math.min(obj.length,Math.max(0,obj.vx * (this.x - obj.x) + obj.vy * (this.y - obj.y)));
  569.                var _loc9_ = obj.x + obj.vx * _loc3_;
  570.                var _loc8_ = obj.y + obj.vy * _loc3_;
  571.                var _loc7_ = this.x - _loc9_;
  572.                var _loc6_ = this.y - _loc8_;
  573.                var _loc10_ = Math.sqrt(_loc7_ * _loc7_ + _loc6_ * _loc6_);
  574.                if(_loc10_ < this.radius)
  575.                {
  576.                   this.startSwing(obj,_loc3_);
  577.                }
  578.                break;
  579.             }
  580.          case SSGlobal.CLSID_ZONE:
  581.             if(obj.boundType)
  582.             {
  583.                if(SSCollision.sweepBoundsToBounds(this,obj))
  584.                {
  585.                   _loc5_ = obj.onCollision(this);
  586.                   this.collisionData = null;
  587.                   return _loc5_ == null ? true : _loc5_;
  588.                }
  589.             }
  590.             else if(SSCollision.sweepSphereToSphere(this,obj,true))
  591.             {
  592.                _loc5_ = obj.onCollision(this);
  593.                this.collisionData = null;
  594.                return _loc5_ == null ? true : _loc5_;
  595.             }
  596.             break;
  597.          case SSGlobal.CLSID_SHAPE:
  598.             if(!obj.disabled && (_loc4_ = SSCollision.sweepSphereToStaticShape(this,obj)))
  599.             {
  600.                if(this.collisionData)
  601.                {
  602.                   if(_loc4_.time < this.collisionData.time)
  603.                   {
  604.                      this.collisionData = _loc4_;
  605.                   }
  606.                   return true;
  607.                }
  608.                this.collisionData = _loc4_;
  609.                return true;
  610.             }
  611.             break;
  612.          case SSGlobal.CLSID_COLLECTABLE:
  613.             if(this.health && SSCollision.sweepSphereToSphere(this,obj,true))
  614.             {
  615.                obj.setCollected(this);
  616.             }
  617.       }
  618.    }
  619.    function shapeCollision(o)
  620.    {
  621.       this.speed = this.velocity.length;
  622.       var _loc4_ = undefined;
  623.       if((_loc4_ = o.edge.attributes.bounciness) == null)
  624.       {
  625.          _loc4_ = 0;
  626.       }
  627.       if(o.edge.attributes.water != null)
  628.       {
  629.          this.setDead("splash",new Vector(o.point.x - o.normal.x * this.radius,o.point.y - o.normal.y * this.radius),true);
  630.          GameSound.playSound("splash");
  631.          return undefined;
  632.       }
  633.       if(this.velocity.y > 600)
  634.       {
  635.          this.shiftHealth(-0.1);
  636.       }
  637.       var _loc6_ = this.velocity.dot(o.normal);
  638.       var _loc3_ = new Vector(_loc6_ * o.normal.x,_loc6_ * o.normal.y,0);
  639.       var _loc5_ = new Vector(this.velocity.x - _loc3_.x,this.velocity.y - _loc3_.y,0);
  640.       this.velocity.x = _loc5_.x - _loc4_ * _loc3_.x;
  641.       this.velocity.y = _loc5_.y - _loc4_ * _loc3_.y;
  642.       this.motionTime -= o.time;
  643.       this.moveTo(o.point.x + o.edge.normal.x * 0.05,o.point.y + o.edge.normal.y * 0.05,0);
  644.       this.corrected = true;
  645.       this.contactSurface = o.edge;
  646.       this.contactNormal = o.normal;
  647.       this.contactPoint = o.point;
  648.       this.onSurfaceContact();
  649.       this.checkCollisions(this.motionTime);
  650.       return true;
  651.    }
  652.    function doCommand(obj, command)
  653.    {
  654.       switch(command.toLowerCase())
  655.       {
  656.          case "loselife":
  657.             this.setDead(obj);
  658.             break;
  659.          case "end":
  660.             this.endLevel(obj);
  661.             break;
  662.          case "climb":
  663.             this.lastClimbingObject = obj;
  664.             break;
  665.          case "machine":
  666.             this.target._visibile = false;
  667.             this.removeDisplay();
  668.             this.world.references.EvilMachine.target.play();
  669.             this.update = function(elapsed)
  670.             {
  671.             };
  672.       }
  673.    }
  674.    function shiftShield(value)
  675.    {
  676.       this.target._visible = true;
  677.       this.shield = Math.min(this.shield + value,this.maxShield);
  678.    }
  679.    function shiftScore(value, obj)
  680.    {
  681.       if(!this.health)
  682.       {
  683.          return false;
  684.       }
  685.       this.controller.shiftScore(value);
  686.       return true;
  687.    }
  688.    function shiftHealth(value, obj)
  689.    {
  690.       if(value < 0 && !this.shield)
  691.       {
  692.          if(this.carrying)
  693.          {
  694.             this.toss();
  695.          }
  696.          else if(this.climbing)
  697.          {
  698.             this.releaseClimb();
  699.          }
  700.          else if(this.swinging)
  701.          {
  702.             this.releaseSwing();
  703.          }
  704.          this.lastClimbTime = this.world.time;
  705.          if(obj)
  706.          {
  707.             this.jumpTime = 0;
  708.             var _loc4_ = undefined;
  709.             var _loc2_ = undefined;
  710.             _loc4_ = new Vector(obj.x <= this.x ? 1 : -1,-1,0);
  711.             if(!(_loc2_ = obj.strength))
  712.             {
  713.                _loc2_ = 200;
  714.             }
  715.             this.velocity.x = _loc4_.x * _loc2_;
  716.             this.velocity.y = _loc4_.y * _loc2_;
  717.             this.stopCol = true;
  718.          }
  719.       }
  720.       if((this.immune || this.shield) && value < 0 || this.health <= 0)
  721.       {
  722.          return false;
  723.       }
  724.       this.controller.health = this.health = Math.max(Math.min(this.health + value,1),0);
  725.       if(this.health <= 0)
  726.       {
  727.          this.setDead(obj);
  728.       }
  729.       else if(value < 0)
  730.       {
  731.          GameSound.playSound("hurt");
  732.          this.lockDisplayState = this.canLockDisplayState;
  733.          this.immune = this.immuneAllowed;
  734.          this.hurt();
  735.          this.onSurfaceContact = function()
  736.          {
  737.             if((this.contactSurface.props & 2) == 0)
  738.             {
  739.                return undefined;
  740.             }
  741.             this.lockDisplayState = false;
  742.             delete this.onSurfaceContact;
  743.             this.onSurfaceContact();
  744.          };
  745.       }
  746.       return true;
  747.    }
  748.    function hurt()
  749.    {
  750.       this.setAnimationState(4,true);
  751.    }
  752.    function setDead(asset, point, hide)
  753.    {
  754.       if(this.dead)
  755.       {
  756.          return undefined;
  757.       }
  758.       if(this.carrying)
  759.       {
  760.          this.toss();
  761.       }
  762.       this.dead = true;
  763.       if(asset != null)
  764.       {
  765.          if(hide)
  766.          {
  767.             this.moveTo(-1000,0,0);
  768.             this.stopCol = true;
  769.          }
  770.          var _loc4_ = new SSParticle(asset,2,new Vector(0,0,0));
  771.          _loc4_.x = point.x;
  772.          _loc4_.y = point.y;
  773.          this.world.addObject(_loc4_);
  774.       }
  775.       if(this.health)
  776.       {
  777.          this.health = 0;
  778.       }
  779.       this.world.viewport.lock();
  780.       GameSound.playSound("LoseLife");
  781.       this.lockDisplayState = true;
  782.       this.keysLocked = true;
  783.       this.onSurfaceContact = function()
  784.       {
  785.          if((this.contactSurface.props & 2) == 0)
  786.          {
  787.             return undefined;
  788.          }
  789.          this.velocity.x = 0;
  790.          this.velocity.y = 1;
  791.          this.setAnimationState(5);
  792.          delete this.onSurfaceContact;
  793.          this.onSurfaceContact();
  794.       };
  795.       var _loc0_ = null;
  796.       var _loc6_ = this.world.engine.onPause = function()
  797.       {
  798.          arguments.callee.cs.pause();
  799.          arguments.callee.obj.target.a.stop();
  800.       };
  801.       var _loc0_ = null;
  802.       var _loc5_ = this.world.engine.onResume = function()
  803.       {
  804.          arguments.callee.cs.resume();
  805.          arguments.callee.obj.target.a.play();
  806.       };
  807.       _loc6_.obj = _loc5_.obj = this;
  808.       var _loc0_ = null;
  809.       var _loc0_ = null;
  810.       var _loc3_ = _loc6_.cs = _loc5_.cs = new CallStack();
  811.       if(this.contactSurface)
  812.       {
  813.          this.setAnimationState(5);
  814.       }
  815.       else
  816.       {
  817.          this.setAnimationState(6);
  818.       }
  819.       _loc3_.wait(3);
  820.       if(this.controller.lives -= 1)
  821.       {
  822.          _loc3_.call(this,this.restore);
  823.       }
  824.       else
  825.       {
  826.          _loc3_.call(this,this.endGame);
  827.       }
  828.       _loc3_.call(this,function()
  829.       {
  830.          delete this.world.engine.onResume;
  831.          delete this.world.engine.onPause;
  832.          delete this.onSurfaceContact;
  833.       }
  834.       );
  835.       _loc3_.start();
  836.    }
  837.    function endGame()
  838.    {
  839.       SSInterface.showScreen("GameOver");
  840.    }
  841.    function endLevel(obj, animated)
  842.    {
  843.       this.immune = 0;
  844.       this.target._visible = true;
  845.       GameSound.stopMusic(0.4);
  846.       this.finished = true;
  847.       this.lockDisplayState = true;
  848.       this.keysLocked = true;
  849.       var _loc2_ = new CallStack();
  850.       if(!this.contactSurface)
  851.       {
  852.          _loc2_.call(this,function()
  853.          {
  854.             return this.contactSurface != null;
  855.          }
  856.          );
  857.       }
  858.       _loc2_.call(this,function()
  859.       {
  860.          this.velocity.x *= 0.5;
  861.          this.velocity.y *= 0.5;
  862.          this.setAnimationState(7,true);
  863.       }
  864.       );
  865.       _loc2_.call(this,function()
  866.       {
  867.          SSInterface.showScreen("WinLevel",true);
  868.       }
  869.       );
  870.       _loc2_.start();
  871.    }
  872.    function setRestorePoint(obj, index)
  873.    {
  874.       this.restorePoint = obj;
  875.    }
  876.    function restore()
  877.    {
  878.       this.dead = false;
  879.       if(this.restorePoint)
  880.       {
  881.          this.moveTo(this.restorePoint.x,this.restorePoint.y - this.radius,0);
  882.       }
  883.       this.setAnimationState(2);
  884.       this.onShieldEnd();
  885.       this.velocity.loc(0,1,0);
  886.       this.controller.health = this.health = 1;
  887.       this.emitParticle(null);
  888.       this.world.viewport.unlock();
  889.       this.world.viewport.setWatch(this);
  890.       this.lockDisplayState = false;
  891.       this.keysLocked = false;
  892.    }
  893. }
  894.